#pragma once

#include "StlWrapper.h"
#include "Events.h"

class ZStream;
class Team;

// do not change order: we need to test >= CardYellowYellow in order to see if a player get Red Card
enum EMatchCards
{
	CardNone = 0,
	CardYellow,
	CardYellowYellow,
	CardRed,
	CardYellowRed
};

inline bool IsNoneCard(const int i_card)
{
	return i_card == CardNone;
}

inline bool IsYellowCard(const int i_card)
{
	return i_card == CardYellow;
}

inline bool IsRedCard(const int i_card)
{
	return i_card >= CardYellowYellow;
}

struct MatchTrainerData
{
	int m_trainerID;
};
typedef STL::vector<MatchTrainerData>			MatchTrainerDataVec;
typedef MatchTrainerDataVec::iterator			MatchTrainerDataVecIt;
typedef MatchTrainerDataVec::const_iterator	MatchTrainerDataVecCIt;

struct MatchPlayerData
{
	int m_playerID;
	int m_goals;
	int m_cards;
	int m_inj;
	int m_stamina;
	int m_evaluation; //percentage
};
typedef STL::vector<MatchPlayerData>			MatchPlayerDataVec;
typedef MatchPlayerDataVec::iterator			MatchPlayerDataVecIt;
typedef MatchPlayerDataVec::const_iterator	MatchPlayerDataVecCIt;

struct MatchTeamData
{
	MatchTeamData();
	void Clear();
	void Init(const Team* const i_team);

	void Serialize(ZStream& o_stream) const;
	void Deserialize(ZStream& i_stream);

	int m_teamID;
	int m_goals;
	MatchPlayerDataVec m_playerData;
	MatchTrainerDataVec m_trainerData;
};

struct MatchData
{
	MatchData();
	void Clear();
	void Init(const Team* const i_t1, const Team* const i_t2);

	bool IsPlayingTeam(const int i_teamID) const;
	const MatchPlayerData* const GetPlayerData(const int i_playerID) const;
	bool IsPlayerMOM(const int i_playerID) const;

	void Serialize(ZStream& o_stream) const;
	void Deserialize(ZStream& i_stream);

	MatchTeamData m_teamData[2];
	EventCollection m_events;
	int m_teamMOM;
	int m_playerMOM;
};

inline	bool MatchData::IsPlayingTeam(const int i_teamID) const
{
	return m_teamData[0].m_teamID == i_teamID || m_teamData[1].m_teamID == i_teamID;
}

inline bool MatchData::IsPlayerMOM(const int i_playerID) const
{
	return m_teamData[m_teamMOM].m_playerData[m_playerMOM].m_playerID == i_playerID;
}